package gjw.jimven.manager;

/**
 * @创建者 Jimven
 * @创建时间 2017/7/12/0012  14:39
 */

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * Activity的管理工具类
 */
public class ActivityManagers {
    private static ActivityManagers manager;
    private        List<Activity>   activityList;

    private ActivityManagers() {
        activityList = new ArrayList<>();
    }

    public static ActivityManagers getIntence() {

        if (manager == null) {
            manager = new ActivityManagers();
        }
        return manager;
    }

    /**
     * 添加Activity到管理工具
     * @param activity
     */
    public void addActivity(Activity activity) {
        if (activityList != null) {
            activityList.add(activity);
        }
    }

    /**
     * 移除Activity
     * @param activity
     */
    public void removeActivity(Activity activity) {
        if (activityList != null && activityList.contains(activity)) {
            activityList.remove(activity);
        }
    }

    /**
     * 结束所有Activity
     */
    public void finishAllActivity() {
        for (Activity activity : activityList
                ) {
            if (activity != null) {
                activity.finish();
            }

        }
    }
}
